;; 一些有用的函数

;; 如果你正在编辑一个东西（在位置A），突然想到别的某处（位置B）要修改或查看
;; 或别的，总之你要过去看看，你可以用C-.来在当前位置做个标记，然后去你想去的
;; 地方B，看了一会你觉的我可以回A去了，用C-,就回到刚才做标记的地方A，再用C-,又会回到B
;; 这个由王垠创作
(defun ska-point-to-register()
  "Store cursorposition _fast_ in a register.
  Use ska-jump-to-register to jump back to the stored
  position."
  (interactive)
  (setq zmacs-region-stays t)
  (point-to-register 8))

(defun ska-jump-to-register()
  "Switches between current cursorposition and position
  that was stored with ska-point-to-register."
  (interactive)
  (setq zmacs-region-stays t)
  (let ((tmp (point-marker)))
    (jump-to-register 8)
    (set-register 8 tmp)))

;; 这个忘了是从哪个地方弄来的，在保存~/.emacs文件自动编译为.elc文件
;; 目前只是对~/.emacs有效，其余的*.el文件还没有去弄，以后有空我会改的
;; 小知识：由于配置文件越来越大，你的*.el配置文件最好都编译为*.elc文件，这样
;; 在启动emacs速度会有很大的提升
;; (defun autocompile nil
;;   "Compile itself if ~/.emacs."
;;   (interactive)
;;   (if (string= (buffer-file-name) (concat default-directory ".emacs"))
;;       (byte-compile-file (buffer-file-name))))
;; (add-hook 'after-save-hook 'autocompile)

;; 自动编译一个目录下的el文件
(defconst dotemacs-basic-conf-dir (concat (file-name-as-directory (getenv "HOME")) ".emacs.d/jerry-lisp/"))
;; (defconst dotemacs-ext-elisp-dir "~/.emacs.d/config/ext-elisp/")
;; (defconst dotemacs-program-dir "~/.emacs.d/config/program/")

(defun autocompile nil
  "Automagically compile change to .emacs and other dotfiles."
  (interactive)
  (cond ((string= (buffer-file-name) (concat default-directory ".emacs"))
	 (byte-compile-file (buffer-file-name)))
	((and (string= (file-name-directory (buffer-file-name))
		       dotemacs-basic-conf-dir)
	      (string= (file-name-extension (buffer-file-name)) "el"))
	 (byte-compile-file (buffer-file-name)))
	)
  )
(add-hook 'after-save-hook 'autocompile)

(provide 'jerry-function)
